package show;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import util.JdbcUtil;

public class Msg_show 
{
	private Connection conn = null;
	private ResultSet rs = null;
	private PreparedStatement ps = null;
	private String table = "message";
	private ArrayList<Msg> msg = null;
	int id;
	
	public Msg_show(int id)
	{
		this.id = id;
		conn = JdbcUtil.getConnection();
		Msg msgt = null;
		msg = new ArrayList<Msg>();
		String find = "select * from "+table+" where SchID="+id;
		try {
			ps = conn.prepareStatement(find);
			rs = ps.executeQuery();
			while(rs.next())
			{
				msgt = new Msg(rs.getString(1), rs.getString(2), rs.getString(3), rs.getTimestamp(4), rs.getInt(5));
//				System.out.println(msgt);
				msg.add(msgt);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			JdbcUtil.release(conn, ps, rs);
		}
	}
	
	public ArrayList<Msg> getMsg() {
		return msg;
	}

//	public static void main(String[] args) 
//	{
//		Msg_show m = new Msg_show(20110000);
//		ArrayList<Msg> info = m.getMsg();
//		for(int i = 0 ;i<info.size() ; i++)
//		{
//			System.out.println(info.get(i).getDate());
//		}
//	}	
}
